package com.sort;

import java.util.Random;

public class FastSort {
    public static void main(String[] args) {
        Random random = new Random();
        int arr[]=new int[100];
        for(int i=0;i<arr.length;i++){
            arr[i]=random.nextInt(1000)+1;
        }
        B.sort_1(arr,0,arr.length-1);
        for(int data:arr){
            System.out.println(data+" ");
        }
//        int arrw[]={1,432,634,74};
//        B.swap(arrw,1,2);
//        for(int data:arrw){
//            System.out.println(data);
//        }

    }
}

class B{
    public static void sort_1(int[] arr,int left,int right){
        if(left>=right){
            return;
        }
        //划分
        int per=partition(arr,left,right);
        sort_1(arr,left,per-1);
        sort_1(arr,per+1,right);
    }

    //划分
    public static int partition(int[]arr,int start,int end){
        int i=start;
        int tem=arr[i];
        while(start<end){
            while(start<end&&tem<=arr[end]){
                end--;
            }
            while(start<end&&tem>=arr[start]){
                start++;
            }
            swap(arr,start,end);
        }
        swap(arr,i,start);
        return start;
    }

    public static void swap(int []arr,int i,int j){
        int tem=arr[i];
        arr[i]=arr[j];
        arr[j]=tem;
    }
}

class C{
    public static void sort_2(int []arr,int left,int right){
        if(left>=right){
            return ;
        }
     //   int per=partmerge();
        //分化


        //合并
   //     merge(arr,left,right,mid);
    }

    public static void merge(int[]arr,int left,int right,int mid){
        int s1=left;
        int e1=mid;
        int s2=mid+1;
        int e2=right;
        int k=0;//合并数组的下标
        int []newarr=new int[left+right-1];
        while(s1<=e1&&s2<=e2){
            if(arr[s1]<=arr[s2]){
                newarr[k++]=arr[s1++];
            }
            else{
                newarr[k++]=arr[s2++];
            }
            while(s1<=e1){
                newarr[k++]=arr[s1++];
            }
            while(s2<e2){
                newarr[k++]=arr[s2++];
            }
        }

    }
}
